home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 1
/
Cream of the Crop 1.iso
/
PROGRAM
/
DBPCXL15.ARJ
/
PCXLIB.DOC
< prev
next >
Wrap
Text File
|
1992-01-26
|
7KB
|
182 lines
------------------------------------------------------------------------------
pcxlib v1.5 by Dave Boynton
(c) 1991
------------------------------------------------------------------------------
This library is hereby placed in the public domain. However, if you'd
like to make a contribution to my efforts to provide a quality product, my
address is:
David Boynton
8083 Budding Br Rd, T-3
Glen Burnie, MD 21061-5077
Any size donation would be welcome.
------------------------------------------------------------------------------
This library currently only supports 256 color pcx files. There are
routines here for 16 color and monochrome files, but none have been tested.
That will be in the next release. Writing to pcx files is now implemented and
tested, although there is no read/modify/write setup.
------------------------------------------------------------------------------
Using the library is simple. Follow these steps and you can't go
wrong (famous last words):
1. Insert '#include "pcxlib.h"' in your source code.
2. Insert 'pcxlib.obj' and 'videof.lib' in your project file, if
using TurboC IDE, or insert in your makefile, command line, or
library, if using something else.
3. Declare pointers to PCXF, a structure that holds key information
about open pcx files. I'll use 'pfile' in this walk-through, so
that would be:
PCXF *pfile;
4. Choose a debug filename and insert 'Start_pcxdebug(filename);'
in an early part of your program, IF you want the library to
output debugging information. For example:
Start_pcxdebug("pcx.dbg");
Remember, this is optional; nothing bad will happen if you don't
do this.
5. Open pcx files with something like:
pfile=fopenPCXr("blast256.pcx");
6. Read from the pcx file with either fread8PCX() or fdisp8PCX().
The latter assumes the use of my vidlib library to set the video
mode. That isn't strictly necessary, all you need do is ensure
that _screen_start, _screen_width, and _screen_length are properly
updated prior to calling fdisp8PCX(). For mode 13h (320x200 by 256
colors), these values should be 0xA0000000L, 320, and 200,
respectively. These variables are declared as externs in vidlib.h.
7. When done, close the file with fclosePCX(pfile), which not only
closes the file, but frees the memory allocated to hold the
structures.
8. If you opened the pcxdebug file, close it with 'Close_pcxdebug();'.
See showpcx.c for a much more readable example.
/* pcxlib.h */
#if !defined(__LARGE__) && !defined(__HUGE__)
#error Wrong memory model
#endif
#ifndef PCX_H /* don't do more than once */
#define PCX_H
#define PCXLIB_VERSION "1.5"
#define ALIGN_DWORD(x) (((x)+3)/4 * 4)
#define What_WPlanes (SQread_reg(2))
#define PCXUNK -1 /* unknown/invalid */
#define PCXMONO 0
#define PCX4colors 1
#define PCX16colors 2
#define PCX256colors 3
struct PCXRGB {
unsigned char r, g, b;
};
typedef struct {
char MagicId;
char Version;
char Encoding;
char BitsPixel;
int Xmin, Ymin;
int Xmax, Ymax;
int Hres, Vres;
struct PCXRGB Palette[16]; /* used only on 16 color pcx's */
char Reserved;
char Planes;
unsigned int bytesline;
int PaletteInfo;
char Filler[58];
} PCXH;
#define MAXAREA 65520L /* 64k - 16 bytes (for malloc) */
typedef struct {
char *name;
FILE *fp;
PCXH *h;
unsigned char *palette; /* for 256 color pcx's w/palette */
long *marks; /* set to NULL when marks not set */
unsigned char *buffer; /* scan line buffer */
int next_scan,buffer_scan;
int type; /* PCXUNK= -1 =unknown/invalid
PCXMONO= 0 =mono
PCX4colors 1 =4 color
PCX16colors= 2 =16 color seg/line
PCX256colors= 3 =256 color */
unsigned w, l;
char cw, cl;
long image_size;
int read_or_write; /* 0 = readonly, 1 = writeonly */
unsigned num_marks; /* set to 0 initially */
} PCXF;
#ifdef _cplusplus
extern "C" {
#endif
PCXF * fopenPCXr(char *name);
PCXF * fopenPCXw(char *name, PCXH *h, char *palette);
int fseekPCX(PCXF *pcxfile, unsigned y); /* seek scan line y */
int fclosePCX(PCXF *pcxfile);
int fread8PCX(char *d, unsigned dw, unsigned dl,
unsigned dx, unsigned dy,
unsigned x0, unsigned y0, unsigned x1, unsigned y1, PCXF *p);
/* fdisp8PCX may be used in VESA modes with no additional work */
/* (other than setting the mode) !! */
int fdisp8PCX(unsigned dx, unsigned dy,
unsigned x0, unsigned y0, unsigned x1, unsigned y1, PCXF *p);
/* fread4PCX reads and converts pixels into a 1 pixel/1 byte format, suitable
for conversion to a different format */
int fread4PCX(char *d, unsigned dw, unsigned dl,
unsigned dx, unsigned dy,
unsigned x0, unsigned y0, unsigned x1, unsigned y1, PCXF *p);
/* fdisp4PCX reads and displays in a VGA planar format */
int fdisp4PCX(unsigned dx, unsigned dy,
unsigned x0, unsigned y0, unsigned x1, unsigned y1, PCXF *p);
/* This function for monochrome .pcx files is untested! I don't have */
/* any mono pcx files to test it with (I'm not interested in mono files). */
int fread1PCX(char *d, unsigned dw, unsigned dl, unsigned dx, unsigned dy,
unsigned x0, unsigned y0, unsigned x1, unsigned y1, PCXF *p);
/* low-level read/write */
unsigned _read_pcx_line(PCXF *pointer, char * linebuffer,
unsigned x0, unsigned x1);
unsigned _write_pcx_line(PCXF *pointer, char * linebuffer,
unsigned x0, unsigned x1,
unsigned char fill);
void _write_pcx_palette(PCXF *pointer);
void _read_palette(PCXF *p);
void Start_pcxdebug(char *path);
void Close_pcxdebug(void);
#ifdef _cplusplus
}
#endif
#ifdef PCX_LIB
int PCXerror=0;
FILE *pcxdebug;
int debugtimeson=0;
#else
extern int PCXerror;
extern FILE *pcxdebug;
extern int debugtimeson;
#endif
#endif /* PCX_lib */